const allContext = {
    rename: {
        id: 'rename',
        text: '重命名',
        icon: 'iconfont icon-zhongmingming',
        hotKey: ['ctrl', 'r']
    },
    deleteNode: {
        id: 'deleteNode',
        text: '删除',
        icon: 'iconfont icon-shanchu',
        hotKey: ['delete']
    },
    deleteLink: {
        id: 'deleteLink',
        text: '删除',
        icon: 'iconfont icon-shanchu',
        hotKey: ['delete']
    },
    copy: {
        id: 'copy',
        text: '复制',
        icon: 'iconfont icon-fuzhi',
        hotKey: ['ctrl', 'c']
    },
    paste: {
        id: 'paste',
        text: '粘贴节点',
        icon: 'iconfont icon-niantiejiedian',
        hotKey: ['ctrl', 'v']
    },
    saveCope: {
        id: 'saveCope',
        text: '保存副本',
        icon: 'iconfont icon-baocunfuben-copy'
    },
    runHistory: {
        id: 'runHistory',
        text: '查看运行历史',
        icon: 'iconfont icon-yunhanglishi-copy'
    },
    revoke: {
        id: 'revoke',
        text: '撤销删除的节点',
        icon: 'iconfont icon-chexiaoshanchudejiedian',
        hotKey: ['ctrl', 'z']
    },
    checkCopy: {
        id: 'checkCopy',
        text: '查看副本',
        icon: 'iconfont icon-tianjiazhushi'
    },
    addComments: {
        id: 'addComments',
        text: '添加注释',
        icon: 'iconfont icon-tianjiazhushi'
    },
    checkReport: {
        id: 'checkReport',
        text: '查看分析报告',
        icon: 'iconfont icon-chakanfenxibaogao'
    },
    executeFromThis: {
        id: 'executeFromThis',
        text: '从此处开始执行',
        icon: 'iconfont icon-congcichukaishizhihang-copy'
    },
    executeToThis: {
        id: 'executeToThis',
        text: '执行到此处',
        icon: 'iconfont icon-zhihangdaocichu-copy'
    },
    executeThis: {
        id: 'executeThis',
        text: '执行该节点',
        icon: 'iconfont icon-zhihanggaijiedian-copy',
        hotKey: ['ctrl', 'shift', 'r']
    },
    executeWithLessData: {
        text: '小数据量试运行',
        icon: 'iconfont icon-kaishizhihang',
        children: [{
                id: 'executeAllInLessData',
                text: '全部执行',
                icon: 'iconfont icon-kaishizhihang'
            },
            {
                id: 'executeFromThisInLessData',
                text: '从此处开始执行',
                icon: 'iconfont icon-congcichukaishizhihang-copy'
            },
            {
                id: 'executeToThisInLessData',
                text: '执行到此处',
                icon: 'iconfont icon-zhihangdaocichu-copy'
            },
            {
                id: 'executeThisInLessData',
                text: '执行该节点',
                icon: 'iconfont icon-zhihanggaijiedian-copy'
            }
        ]
    },
    seeData: {
        id: 'seeData',
        text: '查看数据',
        icon: 'iconfont icon-chakanshuju'
    },
    dataTableOptions: {
        text: '数据表选项',
        icon: 'iconfont icon-read-table',
        children: [{
                id: 'seeDataTable',
                text: '查看数据',
                icon: 'iconfont icon-chakanmoxing',
                children: []
            },
            {
                id: 'saveDataTable',
                text: '保存数据',
                icon: 'iconfont icon-baocunshiyanfuben',
                children: []
            }
        ]
    },
    modelOptions: {
        text: '模型选项',
        icon: 'iconfont icon-moxingxuanxiang',
        children: [{
            id: 'exportPMML',
            text: '导出PMML',
            icon: 'iconfont icon-chakanrizhi'
        }]
    },
    seeLog: {
        id: 'seeLog',
        text: '查看日志',
        icon: 'iconfont icon-chakanrizhi',
        hotKey: ['ctrl', 'l']
    },
    seeModelEvaluationReport: {
        id: 'seeModelEvaluationReport',
        text: '查看模型评估报告',
        icon: 'iconfont icon-chakanshiyanfuben'
    },
    seeTuneHyperParameterReport: {
        id: 'seeTuneHyperParameterReport',
        text: '查看自动调参报告',
        icon: 'iconfont icon-chakanshiyanfuben'
    },
    seeCrossValidation: {
        id: 'seeCrossValidation',
        text: '查看交叉验证报告',
        icon: 'iconfont icon-chakanshiyanfuben'
    },
    seeGenerateRules: {
        id: 'seeGenerateRules',
        text: '查看生成规则报告',
        icon: 'iconfont icon-chakanshiyanfuben'
    },
    close: {
        id: 'close',
        text: '关闭',
        icon: 'iconfont icon-niantiejiedian'
    },
    separator: {
        id: 'separator'
    }
}
const getCommonNodeContextList = (category, outPorts, moduleId, nodeId) => {
    let {
        executeToThis,
        seeLog,
        executeFromThis,
        executeThis,
        checkReport,
        rename,
        deleteNode,
        copy,
        separator,
        modelOptions,
        dataTableOptions
    } = allContext
    let result = [rename, deleteNode, copy, separator]
    if (category === 'model-source') {
        result.splice(0, 1)
    }
    // 检查输出端口是否有数据表或者模型
    let tableDataList = []
    let saveTableDataList = []
    let modelDataList = []
    let saveModelDataList = []
    let tableIndex = 0
    let modelIndex = 0
    for (let i = 0; i < outPorts.length; i++) {
        if (outPorts[i].category === 'table') {
            tableIndex++
            tableDataList.push({
                id: 'seeDataTable',
                text: `查看结果数据表 ${tableIndex > 1 ? tableIndex : ''}`,
                icon: 'iconfont icon-chakanshujubiao',
                parameter: {
                    sequence: outPorts[i].sequence
                }
            })
            saveTableDataList.push({
                id: 'saveDataTable',
                text: `保存结果数据表 ${tableIndex > 1 ? tableIndex : ''}`,
                icon: 'iconfont icon-baocunshiyanfuben',
                parameter: {
                    sequence: outPorts[i].sequence
                }
            })
            continue
        }
        if (outPorts[i].category === 'model') {
            modelIndex++
            modelDataList.push({
                id: 'seeModel',
                text: `查看输出模型 ${modelIndex > 1 ? modelIndex : ''}`,
                icon: 'iconfont icon-chakanmoxing',
                parameter: {
                    sequence: outPorts[i].sequence
                }
            })
            saveModelDataList.push({
                id: 'saveModel',
                text: `保存输出模型 ${modelIndex > 1 ? modelIndex : ''}`,
                icon: 'iconfont icon-baocunshiyanfuben',
                parameter: {
                    sequence: outPorts[i].sequence
                }
            })
            continue
        }
    }
    if (tableIndex > 0) {
        // 如果只有一个输出端口，去除查看数据子节点
        if (tableIndex > 1) {
            tableDataList[0].text = tableDataList[0].text + '1'
            saveTableDataList[0].text = saveTableDataList[0].text + '1'
        }
        dataTableOptions.children = tableDataList.concat(saveTableDataList)
        result.push(dataTableOptions)
    }
    if (modelIndex > 0) {
        if (modelIndex > 1) {
            modelDataList[0].text = modelDataList[0].text + '1'
            saveModelDataList[0].text = saveModelDataList[0].text + '1'
        }
        modelOptions.children = modelDataList.concat(saveModelDataList)
        modelOptions.children.push({
            id: 'exportPMML',
            text: '导出PMML',
            icon: 'iconfont icon-daochu'
        })
        result.push(modelOptions)
    }
    if (category === 'data-source') {
        if (moduleId === 27) {
            result.push(executeToThis, seeLog)
        } else if ([1, 3].includes(moduleId)) {
            result.push(moduleId === 3 ? executeToThis : executeFromThis)
        } else {
            result.push(executeFromThis, seeLog)
        }
    } else if (['model-source', 'model-algorithm'].includes(category)) {
        // 判断源头节点
        result.push(executeFromThis, seeLog)
    } else if (['model-training', 'model-prediction', 'model-evaluation', 'tune-hyperparameter', 'cross-validation', 'statistical-analytics', 'generate-rules', 'model-tune', 'model-cv', 'process'].includes(category)) {
        // 判断计算节点
        result.push(executeFromThis, executeToThis, executeThis, seeLog)
    } else if (['correlation-analysis', 'statistics-analysis'].includes(category)) {
        // 单变量、双变量、关联分析
        checkReport.parameter = {
            moduleId,
            nodeId
        }
        result.push(executeFromThis, executeToThis, executeThis, seeLog, checkReport)
    } else if (['feature-engineeer'].includes(category)) {
        // 特征工程
        checkReport.parameter = {
            moduleId,
            nodeId
        }
        result.push(executeFromThis, executeToThis, executeThis, seeLog)
        if (moduleId === 37) {
            result.push(checkReport)
        }
    }
    return result
}
/**
 * 获取节点菜单，根据节点category
 */
export const getNodeContextList = ({
    category,
    outPorts,
    moduleId,
    nodeId
}) => {
    let result = getCommonNodeContextList(category, outPorts, moduleId, nodeId)
    const obj = {
        'model-tune': 'seeTuneHyperParameterReport',
        'model-cv': 'seeCrossValidation',
        'model-evaluation': 'seeModelEvaluationReport',
        'tune-hyperparameter': 'seeTuneHyperParameterReport',
        'cross-validation': 'seeCrossValidation',
        'generate-rules': 'seeGenerateRules'
    }
    if (Object.keys(obj).includes(category)) {
        result.push(allContext.separator, allContext[obj[category]])
    }
    return result
}
/**
 * 获取容器右键菜单列表
 * @returns {*[]}
 */
export const getContainerContextList = () => {
    const {
        paste,
        revoke,
        checkCopy,
        saveCope,
        runHistory,
        separator
    } = allContext
    return [paste, revoke, separator, saveCope, checkCopy, separator, runHistory]
}
/**
 * 获取连线右键菜单列表
 * @returns {*[]}
 */
export const getLinkContextList = () => {
    return [allContext.deleteLink, allContext.close]
}
